package com.wgke.kmmapp.storage

import com.russhwolf.settings.Settings

/**数据存储*/
class Settings(val set: Settings) {
    fun put(key: String, value: Any) {
        when (value) {
            is Int -> set.putInt(key, value)
            is String -> set.putString(key, value)
            is Float -> set.putFloat(key, value)
            is Double -> set.putDouble(key, value)
            is Boolean -> set.putBoolean(key, value)
            else -> throw (Exception("请使用Int,String,Float,Double,Boolean几种数据"))
        }
    }

    fun getInt(key: String, df: Int = 0): Int = set.getInt(key, df)
    fun getString(key: String, df: String? = null): String = if (df == null) set.getString(key) else set.getString(key, df)
    fun getFloat(key: String, df: Float? = null): Float = if (df == null) set.getFloat(key) else set.getFloat(key, df)
    fun getDouble(key: String, df: Double? = null): Double = if (df == null) set.getDouble(key) else set.getDouble(key, df)
    fun getBoolean(key: String, df: Boolean = false): Boolean = set.getBoolean(key, df)
}